<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>  
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>  
  

<div class="modal" id="articleModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">审核文章</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <!-- 文章的具体内容 -->
      <div class="modal-body" id="articleDetail">
        		
      </div>
      
    </div>
  </div>
</div>

<table class="table">
  <tr>
    <th>id</th>
    <th>标题</th>
    <th>时间</th>
    <th>作者</th>
    <th>栏目</th>
    <th>分类</th>
    <th>状态</th>
    <th>热门</th>
  </tr>
  
  <!-- userPage -->
  <c:forEach items="${articlePage.list}" var="article">
	  <tr>
	    <td>${article.id}</td>
	    <td><a href="javascript:showDeatail(${article.id})">${article.title}</a>
	    </td>
	    <td><fmt:formatDate value="${article.created}" pattern="yyyy-MM-dd"/></td>
	    
	    <td>${article.author==null?'未知':article.author.username}</td>
	    
	    <td>${article.channel.name}</td>
	    <td>${article.category.name}</td>
	    <td>
	         <c:choose>
	    		<c:when test="${article.status==0}">待审核</c:when>
	    		<c:when test="${article.status==1}">通过</c:when>
	    		<c:when test="${article.status==2}">被拒</c:when>
	    		<c:otherwise>不确定</c:otherwise>
	    	 </c:choose>
		</td>
		<td>${article.hot==1?'是热门':'非热门'}</td>
	  </tr>
  </c:forEach>
  
</table>

<nav aria-label="Page navigation example">
  <ul class="pagination">
    <li class="page-item"><a class="page-link" href="javascript:gotoPage(1)">首页</a></li>
    
    <c:forEach begin="${articlePage.pageNum-2>1?articlePage.pageNum-2:1}" 
        end="${articlePage.pageNum+2>articlePage.pages?articlePage.pages:articlePage.pageNum+2}" var="page" step="1"> 
    		<c:if test="${page==articlePage.pageNum}">
    			<li class="page-item"><a class="page-link" href="javascript:void()"><font color="red">${page} </font>  </a></li>
    		</c:if>
    		<c:if test="${page!=articlePage.pageNum}">
    			<li class="page-item"><a class="page-link" href="javascript:gotoPage(${page})">${page}</a></li>
    		</c:if>
     </c:forEach> 
    <li class="page-item"><a class="page-link" href="javascript:gotoPage(${articlePage.pages})">尾页</a></li>
  </ul>
</nav>



<script type="text/javascript">

	function gotoPage(page){
		$("#workContent").load("/admin/articlelist?page="+page)
	}
	
	$('#articleModal').on('hidden.bs.modal', function (e) {
		$("#workContent").load("/admin/articlelist?page="+'${aticlePage.pageNum}')
		})

	function showDeatail(articleId){
		$("#articleDetail").load("/admin/article?id="+articleId);
		$("#articleModal").modal('show');
	}

	function goPage(page){
		$("#workContent").load("/admin/userlist?page="+page)
	}
	
	function userlock(userId,lockStatus){
		
		if(confirm("确实要处理该用户么？")){
			$.post("/admin/userlock",{userid:userId,status:lockStatus},function(msg){
				if(msg=="success"){
					//处理成功
					alert('d')
					$("#workContent").load("/admin/userlist?page="+'${userPage.pageNum}')
				}
			})
		}
	}
	
	// 审核
	function check(id,satus){
		$.get("/admin/checkArticle",{id:id,status:satus},
			function(msg){
				if(msg=="success"){
					alert('审核成功')
					$("#articleModal").modal("hide")
					
				}
			}		
		)
	}
	
	// 设置热门
	function setHot(id,satus){
		$.get("/admin/hotArticle",{id:id,status:satus},
			function(msg){
				if(msg=="success"){
					alert('审核成功')
					$("#articleModal").modal("hide")
				}
			}		
		)
	}
</script>
    